<!doctype html>



  


<html class="theme-next pisces use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.0" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="运维,nginx," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.0" />






<meta name="description" content="前言使用Hexo搭建个人博客项目启动后，其url地址是localhost:4000，使用域名访问也就是jieminblog.tk:4000。但我们平时访问其他网站是一般是没有显示端口号的，当端口号是80端口时,端口号不显示。所以我想让自己的博客访问地址也不带端口号。我查询资料后发现有2种解决方式，一种是把项目的端口号改为80，还有一种就是使用Nginx代理。使用第一种方式的话80端口就不能被其他项">
<meta property="og:type" content="article">
<meta property="og:title" content="Nginx反向代理小应用">
<meta property="og:url" content="http://jieminblog.tk/2017/03/07/Nginx反向代理小应用/index.html">
<meta property="og:site_name" content="jiemin's Blog">
<meta property="og:description" content="前言使用Hexo搭建个人博客项目启动后，其url地址是localhost:4000，使用域名访问也就是jieminblog.tk:4000。但我们平时访问其他网站是一般是没有显示端口号的，当端口号是80端口时,端口号不显示。所以我想让自己的博客访问地址也不带端口号。我查询资料后发现有2种解决方式，一种是把项目的端口号改为80，还有一种就是使用Nginx代理。使用第一种方式的话80端口就不能被其他项">
<meta property="og:updated_time" content="2017-03-07T08:58:19.636Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Nginx反向代理小应用">
<meta name="twitter:description" content="前言使用Hexo搭建个人博客项目启动后，其url地址是localhost:4000，使用域名访问也就是jieminblog.tk:4000。但我们平时访问其他网站是一般是没有显示端口号的，当端口号是80端口时,端口号不显示。所以我想让自己的博客访问地址也不带端口号。我查询资料后发现有2种解决方式，一种是把项目的端口号改为80，还有一种就是使用Nginx代理。使用第一种方式的话80端口就不能被其他项">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Pisces',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":0,"b2t":false,"scrollpercent":false},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://jieminblog.tk/2017/03/07/Nginx反向代理小应用/"/>





  <title> Nginx反向代理小应用 | jiemin's Blog </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  














  
  
    
  

  <div class="container one-collumn sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">jiemin's Blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">本来无一物，何处惹尘埃</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="http://jieminblog.tk/2017/03/07/Nginx反向代理小应用/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="我爱的乌托邦">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/uploads/touxiang.jpeg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="jiemin's Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                Nginx反向代理小应用
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-03-07T15:37:52+08:00">
                2017-03-07
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <h1 id="前言"><a href="#前言" class="headerlink" title="前言"></a>前言</h1><p>使用Hexo搭建个人博客项目启动后，其url地址是<code>localhost:4000</code>，使用域名访问也就是<code>jieminblog.tk:4000</code>。但我们平时访问其他网站是一般是没有显示端口号的，当端口号是80端口时,端口号不显示。所以我想让自己的博客访问地址也不带端口号。我查询资料后发现有2种解决方式，一种是把项目的端口号改为80，还有一种就是使用<strong>Nginx</strong>代理。使用第一种方式的话80端口就不能被其他项目所使用，而使用<strong>Nginx</strong>代理方式80端口还可以被其他服务所使用，理所当然的我选择了第二种方式。<br><a id="more"></a></p>
<h1 id="安装和配置Nginx"><a href="#安装和配置Nginx" class="headerlink" title="安装和配置Nginx"></a>安装和配置Nginx</h1><p>使用yum安装nginx</p>
<p><code>yum install nginx</code></p>
<p>启动nginx</p>
<p><code>systemctl start nginx</code></p>
<p>配置nginx</p>
<figure class="highlight nginx"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div></pre></td><td class="code"><pre><div class="line"><span class="section">server</span> &#123;</div><div class="line">       <span class="attribute">listen</span>       <span class="number">80</span>;</div><div class="line">       <span class="attribute">server_name</span>  jieminblog.tk www.jieminblog.tk;</div><div class="line"></div><div class="line">       <span class="comment"># Load configuration files for the default server block.</span></div><div class="line"></div><div class="line">       <span class="attribute">location</span> / &#123;</div><div class="line">            <span class="attribute">proxy_pass</span> http://127.0.0.1:4000/;</div><div class="line">       &#125;</div><div class="line"></div><div class="line"></div><div class="line">       <span class="attribute">error_page</span> <span class="number">404</span> /<span class="number">404</span>.html;</div><div class="line">           <span class="attribute">location</span> = /40x.html &#123;</div><div class="line">       &#125;</div><div class="line"></div><div class="line">       <span class="attribute">error_page</span> <span class="number">500</span> <span class="number">502</span> <span class="number">503</span> <span class="number">504</span> /50x.html;</div><div class="line">           <span class="attribute">location</span> = /50x.html &#123;</div><div class="line">       &#125;</div><div class="line">   &#125;</div></pre></td></tr></table></figure>
<p>保存后重启nginx</p>
<p><code>systemctl restart nginx</code></p>
<h1 id="配置中遇到的问题"><a href="#配置中遇到的问题" class="headerlink" title="配置中遇到的问题"></a>配置中遇到的问题</h1><p>Nginx启动或重启失败</p>
<p><strong>原因:</strong> 80端口被占用启动失败</p>
<p><strong>解决办法:</strong></p>
<ol>
<li><p>查看是什么占用了80端口</p>
<p><code>lsof -i tcp:80</code></p>
</li>
<li><p>根据上述查询结果得到占用80端口的PID,强行杀死进程。</p>
<p><code>kill -9 PID</code> </p>
</li>
<li><p>重复第一步，如果没有进程存在就重启nginx服务，如果还存在进程，查看进程详细信息，<code>ps PID</code>，这是会显示进程的启动目录，进入目录使用<code>stop</code>命令即可，如果不存在则命令行有提示怎么关闭进程。</p>
</li>
</ol>
<h1 id="结束语"><a href="#结束语" class="headerlink" title="结束语"></a>结束语</h1><p>这个是<strong>Nginx</strong>的简单的配置，虽然简单，但切切实实的解决了一个问题–使域名后面不加端口号。关于<strong>Ngnix</strong>我只是初窥门径，目前也暂时没有项目能和 <strong>Nginx</strong>结合使用，所以能写的也只有这些。将来如果有深入了解 <strong>Nginx</strong>，再来详写！</p>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>


    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/运维/" rel="tag"># 运维</a>
          
            <a href="/tags/nginx/" rel="tag"># nginx</a>
          
        </div>
      

      
        
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/03/07/Centos7下搭建openvpn/" rel="next" title="Centos7下搭建openvpn">
                <i class="fa fa-chevron-left"></i> Centos7下搭建openvpn
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/03/08/vi学习笔记/" rel="prev" title="vi学习笔记">
                vi学习笔记 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>

          
          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/uploads/touxiang.jpeg"
               alt="我爱的乌托邦" />
          <p class="site-author-name" itemprop="name">我爱的乌托邦</p>
           
              <p class="site-description motion-element" itemprop="description"></p>
          
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
              <a href="/archives">
                <span class="site-state-item-count">17</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/tags/index.html">
                <span class="site-state-item-count">15</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#前言"><span class="nav-number">1.</span> <span class="nav-text">前言</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#安装和配置Nginx"><span class="nav-number">2.</span> <span class="nav-text">安装和配置Nginx</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#配置中遇到的问题"><span class="nav-number">3.</span> <span class="nav-text">配置中遇到的问题</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#结束语"><span class="nav-number">4.</span> <span class="nav-text">结束语</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">我爱的乌托邦</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Pisces
  </a>
</div>


        

        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    
    
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  




  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.0"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.0"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.0"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.0"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.0"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.0"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.0"></script>



  



  




	





  





  





  



  
  

  

  

  

  


  

</body>
</html>
